package com.mediators
{
	import com.AppConfing;
	import com.messagers.AppLoadExportUISkin;
	import com.messagers.AppLoadUIMessager;
	import com.messagers.MouseMessager;
	import com.models.UIBaseProxy;
	import com.views.UIBase;
	import com.vo.ButtonVO;
	
	import feathers.controls.Button;
	import feathers.controls.List;
	import feathers.data.ListCollection;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import starling.events.Event;
	import starling.textures.Texture;
	/**
	 * 通用基础界面mediator 
	 * @author shishujun
	 * 
	 */	
	public class UIBaseMediator extends Mediator implements IMediator
	{
		public const NAME : String = "UIBaseMediator";
		private var _viewComponent : UIBase;
		private var _uibaseproxy : UIBaseProxy;
		
		public function UIBaseMediator(viewComponent : UIBase)
		{
			super(NAME, viewComponent);
			_viewComponent = viewComponent;
			_uibaseproxy = facade.retrieveProxy(UIBaseProxy.NAME) as UIBaseProxy;
			_uibaseproxy.loadbaseUIAssets();
		}
		
		public override function listNotificationInterests():Array
		{
			return [AppConfing.BASEUI_LOADCOMPLETE];
		}
		
		public override function handleNotification(notification:INotification):void
		{
			var noteType : String = notification.getName();
			switch(noteType)
			{
				case AppConfing.BASEUI_LOADCOMPLETE : 
					trace("mediator接收到了加载完成的消息……");
					var basecomponentData : Array = AppLoadExportUISkin.BasecomponentData;
					var listCollection : ListCollection = new ListCollection();
					var length : int = basecomponentData.length;
					for(var i : int = 0; i < length; ++i)
					{
						_viewComponent.list.itemRendererProperties.labelField = "name";
						_viewComponent.list.itemRendererProperties.iconSourceField = "texture";
						listCollection.addItem(basecomponentData[i]);
					}
					_viewComponent.list.dataProvider = listCollection;
					
					_viewComponent.list.addEventListener(Event.CHANGE, onlistChange);
					break;
			}
		}
		
		private function onlistChange(event : Event) : void
		{
			var list:List = List( event.currentTarget );
			trace( "selectedIndex:", list.selectedIndex, list.selectedItem.name);
			var itemname : String = list.selectedItem.name;
			switch(itemname)
			{
				case AppConfing.BUTTON :
					var buttonvo : ButtonVO = _uibaseproxy.buttonObj[AppConfing.baseBtnKey];
					MouseMessager.Hander(buttonvo);
					break;
			}
			
			
		}
		
	}
}